package com.rongsheng.mpchartdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.github.mikephil.charting.charts.BarChart;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class BarChartActivity extends AppCompatActivity {

    private BarChart barChart1;

    private List<String> xAxisValues;
    String[] xdata={"1","2","3","4","5","6","7","8","9","10","11","12"};
    private List<Float> yAxisValues;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bar_chart);

        initView();
        initData();
        MPChartHelper.setBarChart(barChart1,xAxisValues,yAxisValues,"柱状图（单）",15,null);
        barChart1.setVisibleXRangeMaximum(6f);
    }

    private void initView(){
        barChart1=(BarChart)findViewById(R.id.barChart1);
    }

    private void initData(){
        xAxisValues = new ArrayList<>();
        yAxisValues = new ArrayList<>();
        for(int i=1;i<xdata.length;++i){
//            xAxisValues.add(String.valueOf(i));
            Collections.addAll(xAxisValues, xdata);
            yAxisValues.add((float)(Math.random()*100+20));
        }
    }
}
